import { Reducer, Effect, Subscription } from 'umi';
import {
  getStudentClassTwoByType,
  getStudentListFromSerices,
  getStudentClassTwoBystudentCode,
} from '@/services/StudentAnalysisHuang';
/*
-----------------------------------------------------------------------------------------------------------------
本model用来演示简便的流程，即不通过reducers和state仓库直接在effects中返回
①组件连接仓库；
②组件通过connect连接后给组件自动传的参数dispatch访问仓库中的异步函数effects；
③effects获取到数据后调用callBack回调函数返回数据
④组件通过callback获取回调数据
-----------------------------------------------------------------------------------------------------------------
 */

/*
-----------------------------------------------------------------------------------------------------------------
ts规范：对变量进行声明
 */
//对state声明，state用于仓库存储数据，也就是说state就是仓库
export type StateType = {
  accountId?: any;
  currentRoleId?: any;
  studentList?: any; //二课学生列表
  studentDetialList?: any; //二课详情列表
};
//对model声明
export type GraduationSurveyTeacherModelType = {
  namespace: string;
  state: StateType;
  effects: {
    getStudentClassTwoByType: Effect; //获取学生二课成绩
    getStudentListFromSerices: Effect;
    getStudentClassTwoBystudentCode: Effect; //获取单个学生二课成绩
  };
  reducers: {
    setStudentListReducer: Reducer; //设置获取的学生列表
    setstudentDetialListReducer: Reducer; //设置获取的学生二课信息
  };
  subscriptions: {};
};
/*
ts规范：对变量进行声明
-----------------------------------------------------------------------------------------------------------------
 */

/*
-----------------------------------------------------------------------------------------------------------------
model结构：namespace，state（仓库，用来存储数据），
effects异步处理，reducers同步操作（用于接收effects的结果并存到state中），subscription订阅（用于监听页面的跳转）
state变化后，连接此model的组件所接收到的参数会自动渲染
 */
const StudentAnalysisHuang: GraduationSurveyTeacherModelType = {
  //本model唯一标识，命名标准：不能有'-'，可以有'_'，可以有大写
  //个人标准：以后都以'Model_'开头
  namespace: 'StudentAnalysisHuang', //Model_ExampleModel里面存的是state
  state: {
    accountId: '',
    currentRoleId: '',
    studentList: [],
    studentDetialList: {},
  },
  //命名规范（个人）：函数功能+FromServices+Effects
  effects: {
    *getStudentClassTwoByType({ payload }: any, { call, put }: any): Generator {
      //: Generator解决yield报红
      const token = localStorage.getItem('token');
      //const result = yield call(getStudentClassTwoByType, token, payload);
      let list = [
        {
          Id: 1,
          userId: '181418',
          userName: '佘甲帅',
          calssName: '计183',
          Grade: '2022',
          majiorName: '计算机科学与技术专业',
          calsserTeacher: '刘洪普',
          Score: 999,
          Ranking: 1,
          Score1: 1,
          Score2: 2,
          Score3: 3,
          Score4: 4,
        },
        {
          Id: 2,
          userId: '185853',
          userName: '陈晓冲',
          calssName: '计183',
          Grade: '2022',
          majiorName: '计算机科学与技术专业',
          calsserTeacher: '候向丹',
          Score: 999,
          Ranking: 2,
          Score1: 5,
          Score2: 6,
          Score3: 7,
          Score4: 8,
        },
      ];
      payload.callback(list);
      yield put({
        type: 'setStudentListReducer',
        //payload: result.data.data,
        payload: list,
      });
    },
    *getStudentClassTwoBystudentCode(
      { payload }: any,
      { call, put }: any,
    ): Generator {
      let token = localStorage.getItem('token');
      let list = {
        code: 200,
        msg: '查找成功！',
        data: {
          studentCode: '194765',
          studentName: '余霖辉',
          sex: '男',
          enrollment: '201909',
          programme: 4,
          mentorName: '李华',
          overallGrade: 31.11,
          classRank: 1,
          majorRank: 6,
          firstYear: {
            dimensionOne: {
              idealsBeliefs: 7.9,
              practicalService: 7.0,
              literatureArt: 0.0,
              academicTechnology: 9.18,
              socialWork: 1.1,
              physicalFitness: 1.4,
            },
            dimensionTwo: {
              activitiesCompetitions: 26.13,
              awardsHonors: 6.48,
              studentOrganization: 3.0,
            },
            dimensionThree: {
              collegeLevel: 9.05,
              universityLevel: 12.16,
              provincialLevel: 4.4,
              nationalLevel: 4.0,
            },
            totalGrade: 87.3,
          },
          secondYear: {
            dimensionOne: {
              idealsBeliefs: 7.9,
              practicalService: 7.0,
              literatureArt: 0.0,
              academicTechnology: 9.18,
              socialWork: 1.1,
              physicalFitness: 1.4,
            },
            dimensionTwo: {
              activitiesCompetitions: 26.13,
              awardsHonors: 6.48,
              studentOrganization: 3.0,
            },
            dimensionThree: {
              collegeLevel: 9.05,
              universityLevel: 12.16,
              provincialLevel: 4.4,
              nationalLevel: 4.0,
            },
            totalGrade: 87.3,
          },
          thirdYear: {
            dimensionOne: {
              idealsBeliefs: 7.9,
              practicalService: 7.0,
              literatureArt: 0.0,
              academicTechnology: 9.18,
              socialWork: 1.1,
              physicalFitness: 1.4,
            },
            dimensionTwo: {
              activitiesCompetitions: 26.13,
              awardsHonors: 6.48,
              studentOrganization: 3.0,
            },
            dimensionThree: {
              collegeLevel: 9.05,
              universityLevel: 12.16,
              provincialLevel: 4.4,
              nationalLevel: 4.0,
            },
            totalGrade: 87.3,
          },
          forthYear: {
            dimensionOne: {
              idealsBeliefs: 7.9,
              practicalService: 7.0,
              literatureArt: 0.0,
              academicTechnology: 9.18,
              socialWork: 1.1,
              physicalFitness: 1.4,
            },
            dimensionTwo: {
              activitiesCompetitions: 26.13,
              awardsHonors: 6.48,
              studentOrganization: 3.0,
            },
            dimensionThree: {
              collegeLevel: 9.05,
              universityLevel: 12.16,
              provincialLevel: 4.4,
              nationalLevel: 4.0,
            },
            totalGrade: 87.3,
          },
        },
      };
      const result: any = yield call(
        getStudentClassTwoBystudentCode,
        token,
        payload.value,
      );

      yield put({
        type: 'setstudentDetialListReducer',
        payload: result.data.data,
        //payload: list.data,
      });
    },
    *getStudentListFromSerices(
      { payload }: any,
      { call, put }: any,
    ): Generator {
      let token = localStorage.getItem('token');
      let list = [
        {
          Id: 1,
          userId: '181418',
          userName: '黄天博',
          calssName: '计183',
          Grade: '2022',
          majiorName: '人工智能',
          calsserTeacher: '顾军华',
          Score: 999,
          Ranking: 1,
          Score1: 9,
          Score2: 10,
          Score3: 11,
          Score4: 12,
        },
        {
          Id: 2,
          userId: '185853',
          userName: '郑海飞',
          calssName: '计183',
          Grade: '2022',
          majiorName: '人工智能',
          calsserTeacher: '顾军华',
          Score: 999,
          Ranking: 2,
          Score1: 13,
          Score2: 14,
          Score3: 15,
          Score4: 16,
        },
      ];
      //const result: any = yield call(getStudentListData, token, payload.value);

      yield put({
        type: 'setStudentListReducer',
        //payload: result.data.data,
        payload: list,
      });
    },
  },
  //命名规范（个人）：函数功能+Reducers
  reducers: {
    setStudentListReducer(state, { payload }) {
      return { ...state, studentList: payload };
    },
    setstudentDetialListReducer(state, { payload }) {
      return { ...state, studentDetialList: payload };
    },
  },

  subscriptions: {},
};
/*
model结构
-----------------------------------------------------------------------------------------------------------------
 */

export default StudentAnalysisHuang;
